#include<bits/stdc++.h>
using namespace std;
int a[100010],b[100010],c[100010];
int g(int x,int y)
{
	return y-x+b[x-1]-b[y];
}
int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		b[i]=b[i-1];
		if(!c[a[i]]) b[i]++;
		c[a[i]]++;
		//cout<<b[i]<<" ";
	}
	int maxs=-1e9;
	for(int i=1;i<=n;i++)
	{
		for(int j=i;j<=n;j++)
		{
			maxs=max(maxs,j-i+b[i-1]-b[j]);
		}
	}
	cout<<maxs;
	return 0;
} 
